package com.mark.web.data.controller.portal;

import com.mark.common.CurrentUser;
import com.mark.common.ServerResponse;
import com.mark.web.data.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Description: 订单Controller
 * @Author: Mark
 * @CreateDate: 2018/8/14.
 * @Version: 2.0
 * @Copyright : 豆浆油条个人非正式工作室
 */
@RestController
@RequestMapping("/order/")
@Slf4j
public class OrderController {
    @Autowired
    private IOrderService iOrderService;

    /**
     * 1.创建订单
     * @param shippingId:收货地址id
     * @return ：
     */
    @PostMapping(value = "create.do")
    @ResponseBody
    public ServerResponse create(Integer shippingId){
        return iOrderService.createOrder(CurrentUser.getCurrentUserId(),shippingId);
    }


    //2.取消订单
    @RequestMapping("cancel")
    @ResponseBody
    public ServerResponse cancel(Long orderNo){
        return iOrderService.cancelOrder(CurrentUser.getCurrentUserId(),orderNo);
    }

    /**
     * 3.获取购物车中已经选中的商品详情提交订单时候调用
     * @return :
     */
    @PostMapping(value = "get_order_cart_product.do")
    @ResponseBody
    public ServerResponse getOrderCartProduct(){
        return iOrderService.getOrderCartProduct(CurrentUser.getCurrentUserId());
    }

    //4.返回订单详情
    @RequestMapping("detail.do")
    @ResponseBody
    public ServerResponse detail(Long orderNo){
        return iOrderService.getOrderDetail(CurrentUser.getCurrentUserId(),orderNo,null);
    }

    /**
     * 分页查看订单列表
     * @param pageNum：当前页数
     * @param pageSize：页面大小
     * @return ：
     */
    @ResponseBody
    @PostMapping(value = "list.do")
    public ServerResponse list(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                               @RequestParam(value = "pageSize", defaultValue = "10") int pageSize){
        return iOrderService.getOrderList(CurrentUser.getCurrentUserId(),pageNum,pageSize);
    }


    //2.确认收货
    @RequestMapping(value = "getGoods.do",method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse getGoods(Long orderNo){
        return iOrderService.getGoods(CurrentUser.getCurrentUserId(),orderNo);
    }

}
